import Vue from 'vue'
import 'es6-promise/auto'
import Vuex from 'vuex'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

let userInfo = {
    name: '',
    credits: 0,
    unitRanking: 0,
    collegeRanking: 0,
    cumulativeHours: 0,
    examsCount: 0,
    waitWorkCount: 0,
    todoCount: 0
}

if (localStorage.getItem('userInfo')) {
    userInfo = JSON.parse(localStorage.getItem('userInfo'))
}

window.store = new Vuex.Store({
    state: {
        userInfo: userInfo,
        activeMenu: '',
        activeCurriculumType: 0,
        curriculumTypeList: [],
        activeCurriculumId: '',
        isShowLoginDialog: false,
        learningCommunityType: 1
    },
    mutations: {
        updateActiveMenu(state, val) {
            state.activeMenu = val
        },
        updateActiveCurriculumType(state, payload) {
            state.activeCurriculumType = payload
        },
        updateCurriculumTypeList(state, payload) {
            state.curriculumTypeList = payload
        },
        updateactiveCurriculumId(state, payload) {
            state.activeCurriculumId = payload
        },
        setUserInfo(state, val) {
            state.userInfo = val
            localStorage.setItem('userInfo', JSON.stringify(val))
        },
        exit(state) {
            state.userInfo.name = ''
        },
        showLoginDialog(state, val) {
            state.isShowLoginDialog = val
        },
        switchLearningCommunityType(state, val) {
            state.learningCommunityType = val
        }
    },
    modules: {
    },
    strict: debug
})

export default window.store